package com.mswork.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mswork.common.annotation.Log;
import com.mswork.common.core.controller.BaseController;
import com.mswork.common.core.domain.AjaxResult;
import com.mswork.common.enums.BusinessType;
import com.mswork.mes.domain.Auxiliary;
import com.mswork.mes.service.IAuxiliaryService;
import com.mswork.common.utils.poi.ExcelUtil;
import com.mswork.common.core.page.TableDataInfo;

/**
 * 辅料库存Controller
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/mes/auxiliary")
public class AuxiliaryController extends BaseController {
    @Autowired
    private IAuxiliaryService auxiliaryService;

    /**
     * 查询辅料库存列表
     */
    @PreAuthorize("@ss.hasPermi('mes:auxiliary:list')")
    @GetMapping("/list")
    public TableDataInfo list(Auxiliary auxiliary) {
        startPage();
        List<Auxiliary> list = auxiliaryService.selectAuxiliaryList(auxiliary);
        return getDataTable(list);
    }

    @PostMapping("/listByAuxiliaryType")
    public AjaxResult listByAuxiliaryType(@RequestBody Auxiliary auxiliary) {
        List<Auxiliary> list = auxiliaryService.selectAuxiliaryByAuxiliaryType(auxiliary);
        return success(list);
    }

    /**
     * 导出辅料库存列表
     */
    @PreAuthorize("@ss.hasPermi('mes:auxiliary:export')")
    @Log(title = "辅料库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Auxiliary auxiliary) {
        List<Auxiliary> list = auxiliaryService.selectAuxiliaryList(auxiliary);
        ExcelUtil<Auxiliary> util = new ExcelUtil<Auxiliary>(Auxiliary.class);
        util.exportExcel(response, list, "辅料库存数据");
    }

    /**
     * 获取辅料库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:auxiliary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(auxiliaryService.selectAuxiliaryById(id));
    }

    /**
     * 新增辅料库存
     */
    @PreAuthorize("@ss.hasPermi('mes:auxiliary:add')")
    @Log(title = "辅料库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Auxiliary auxiliary) {
        return toAjax(auxiliaryService.insertAuxiliary(auxiliary));
    }

    /**
     * 修改辅料库存
     */
    @PreAuthorize("@ss.hasPermi('mes:auxiliary:edit')")
    @Log(title = "辅料库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Auxiliary auxiliary) {
        return toAjax(auxiliaryService.updateAuxiliary(auxiliary));
    }

    /**
     * 删除辅料库存
     */
    @PreAuthorize("@ss.hasPermi('mes:auxiliary:remove')")
    @Log(title = "辅料库存", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(auxiliaryService.deleteAuxiliaryByIds(ids));
    }
}
